//package cn.itsource.ymcc.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.baomidou.mybatisplus.core.parser.ISqlParser;
//import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
//import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import io.seata.rm.datasource.DataSourceProxy;
//import org.apache.ibatis.plugin.Interceptor;
//import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//
//import javax.sql.DataSource;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 数据源代理
// */
//@Configuration
//public class DataSourceConfiguration {
//
//    //mapper.xml路径
//    @Value("${mybatis-plus.mapper-locations}")
//    private String mapperLocations;
//
//    //手动配置bean
//    @Bean
//    @ConfigurationProperties("spring.datasource")
//    public DataSource dataSource(){
//        return new DruidDataSource();
//    }
//
//    @Bean
//    public MybatisSqlSessionFactoryBean sqlSessionFactoryBean(DataSourceProxy dataSourceProxy) throws Exception {
//        //处理MybatisPlus
//        MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
//        factory.setDataSource(dataSourceProxy);
//        factory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
//        //事务管理工厂
//        factory.setTransactionFactory(new SpringManagedTransactionFactory());
//
//
//        //分页插件处理
//        //mybtis-plus分页拆件
//        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//        //攻击SQL阻断解析器,加入解析链
//        List<ISqlParser> sqlList = new ArrayList<>();
//        sqlList.add(new BlockAttackSqlParser());
//        paginationInterceptor.setSqlParserList(sqlList);
//        factory.setPlugins(new Interceptor[]{paginationInterceptor,new OptimisticLockerInterceptor()});
//
//        return factory;
//    }
//
//    @Bean
//    public DataSourceProxy dataSourceProxy(DataSource dataSource) {
//        return new DataSourceProxy(dataSource);
//    }
//
//}